package com.daohang361.imqq.tool;

import java.io.UnsupportedEncodingException;
import com.daohang361.imqq.Asycore.MyLoger;

/**
 * 此程序采用暴力方法解已经解密的16进制数据,从头部开始依次一个字节俩个字节....直到结束转换
 * 假设一个byte数组长度为10 则暴力解密次数 =10+9+8+7+6+5+4+3+2+1=(10+1)*10/2=55次
 * @author naner
 */
public class ViolenceBytes {
	private byte[] initByte=null;
	public ViolenceBytes(byte[] initByte){
		this.initByte=initByte;
	}
	
	public void violence(int start,int end)
	{
		MyLoger.writeLog("暴力开始");
		for(int i=start;i<=end;i++){
			for(int j=i;j<=end;j++)
			{
				byte[] temp=new byte[j-i+1];
				System.arraycopy(initByte, i, temp, 0, j-i+1);
				try {
					
					MyLoger.writeLog(Hex2Bytes.bytesToHexString(temp)+" TO UTF-8:"+new String(temp,"UTF-8"));
					MyLoger.writeLog(Hex2Bytes.bytesToHexString(temp)+" TO GBK:"+new String(temp,"GBK"));
					MyLoger.writeLog(Hex2Bytes.bytesToHexString(temp)+" TO INT:"+MyUtil.bytes2Integer(temp));
				} catch (UnsupportedEncodingException e) {
					MyLoger.writeLog(Hex2Bytes.bytesToHexString(temp)+" TO UTF-8 失败!");
				}catch (NumberFormatException e){
					MyLoger.writeLog(Hex2Bytes.bytesToHexString(temp)+" TO INT 失败!");
				}
			}
		}
		MyLoger.writeLog("暴力结束");
	}

	public void violence(){
		violence(0,initByte.length-1);
	}
	
}
